import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

//4:baidu ArrayList和LinkedList实现原理，并比较性能
// （操作加入新值100000次，随机删除100个值，比较时间）
public class Work {
    public static void main(String[] args) {
        int count = 0;
        List list1 = new ArrayList();
        long start1 = System.nanoTime();
        for (int i = 0; i < 100000; i++) {
            list1.add(i);
        }
        for (int i = 0; i < 100; i++) {
            count = (int) (Math.random() * ((list1.size() - 1) - 0 + 1) + 1);
            list1.remove(count);
        }
        long stop1 = System.nanoTime();
        long time1 = stop1 - start1;
        List list2 = new LinkedList();
        long start2 = System.nanoTime();
        for (int i = 0; i < 100000; i++) {
            list2.add(i);
        }
        for (int i = 0; i < 100; i++) {
            count = (int) (Math.random() * ((list2.size() - 1) - 0 + 1) + 1);
            list1.remove(count);
        }
        long stop2 = System.nanoTime();
        long time2 = stop2 - start2;
        System.out.println("ArrayList的时间是：" + time1 + "纳秒" + "\nLinkedList的时间是：" + time2 + "纳秒");
    }
}
